package com.knshare.utils;

import com.knshare.utils.Executor.PoolTaskExecutor;
import com.knshare.utils.Executor.ThreadPoolExecutorService;

/**
 * 线程池工具
 * @author rongxun.wu01
 * @product IntelliJ IDEA
 * @project KnShare
 * @Date 2023-05-06 15:11
 */
public class ThreadUtil {
    public ThreadUtil() {
    }

    /**
     * 创建新新线程池
     * @param corePoolSize
     * @return
     */
    public static ThreadPoolExecutorService newExecutor(int corePoolSize) {
        return  PoolTaskExecutor.create().setCorePoolSize(corePoolSize).CratePoolTaskExecutor();
    }

    /**
     * 创建新新线程池
     * @param corePoolSize
     * @return
     */
    public static ThreadPoolExecutorService newExecutor(int corePoolSize,int maxPoolSize) {
        return  PoolTaskExecutor.create().setCorePoolSize(corePoolSize).setMaxPoolSize(maxPoolSize).CratePoolTaskExecutor();
    }

    /**
     *
     * @param corePoolSize
     * @param maxPoolSize
     * @param keepAliveTime  默认 SECONDS
     * @return
     */
    public static ThreadPoolExecutorService newExecutor(int corePoolSize,int maxPoolSize,long keepAliveTime) {
        return  PoolTaskExecutor.create().setCorePoolSize(corePoolSize).setMaxPoolSize(maxPoolSize).setKeepAliveTime(keepAliveTime).CratePoolTaskExecutor();
    }
}
